package cn.edu.guet.controller;


import cn.edu.guet.bean.postlist.Zmpost;
import cn.edu.guet.service.postlist.IZmpostService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;


@Controller
@RequestMapping("zmpost")
public class ZmpostController {

    @Autowired
    private IZmpostService zmpostService;

    @GetMapping("zuiretiezi")
    public String zuiretiezi(HttpServletRequest request, Model model){
        String ptitle=request.getParameter("ptitle");
        String ptype=request.getParameter("ptitle");
        List<Zmpost> zmposts=zmpostService.zuiretiezi(ptitle,ptype);
        model.addAttribute("zmposts",zmposts);
        return "zuiretiezi";
//        request.setAttribute("zmposts", zmpostService.zuiretiezi());
//        return "zuiretiezi";
    }

    @GetMapping("zuixinfabiao")
    public String zuixinfabiao(HttpServletRequest request, Model model){
        String ptitle=request.getParameter("ptitle");
        String ptype=request.getParameter("ptitle");
        List<Zmpost> zmposts=zmpostService.zuixinfabiao(ptitle,ptype);
        model.addAttribute("zmposts",zmposts);
        return "zuixinfabiao";
    }

    @GetMapping("zuzhizuire")
    public String zuzhizuire(HttpServletRequest request, Model model){
//        String gid="1";
        List<Zmpost> zmpost=zmpostService.dgroupList();
        model.addAttribute("zmpost", zmpost);

        String gid=request.getParameter("gid");
        if(gid!=null) {
            List<Zmpost> zmposts = zmpostService.zuzhizuire(gid);
            model.addAttribute("zmposts", zmposts);
        }else {
            List<Zmpost> zmposts = zmpostService.viewone();
            model.addAttribute("zmposts", zmposts);
        }
        return "zuzhizuire";
    }

    @GetMapping("zuzhizuixin")
    public String zuzhizuixin(HttpServletRequest request, Model model){
        List<Zmpost> zmpost=zmpostService.dgroupList();
        model.addAttribute("zmpost", zmpost);

        String gid=request.getParameter("gid");
//        System.out.println("取到前台传到后台的数据是："+gid);
        if(gid!=null) {
            List<Zmpost> zmposts = zmpostService.zuzhizuixin(gid);
            model.addAttribute("zmposts", zmposts);
        }else {
            List<Zmpost> zmposts = zmpostService.viewtwo();
            model.addAttribute("zmposts", zmposts);
        }
        return "zuzhizuixin";
    }
}
